package com.depin.pdaapp.application;


import android.app.ActivityManager;
import android.content.Context;
import android.device.ScanManager;
import android.device.scanner.configuration.Triggering;
import android.util.Log;

import androidx.multidex.MultiDex;

import com.depin.pdaapp.bean.ProvinceDataBean;
import com.depin.pdaapp.event.ActivityLifecycleListener;
import com.depin.pdaapp.utils.ApplicationHelper;
import com.jaydenxiao.common.baseapp.BaseApplication;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.vondear.rxtool.RxTool;
import com.xuexiang.xui.XUI;

import java.util.List;


/**
 * Created by lzn.
 * Date：2020/2/14 13:38
 * Desc：
 **/
public class MyApplication extends BaseApplication {
    private IWXAPI api;
    private ScanManager manager;

    @Override
    public void onCreate() {
        super.onCreate();
        XUI.init(this); //初始化UI框架
        XUI.debug(true);  //开启UI框架调试日志
        RxTool.init(this);
        MultiDex.install(this);
        ApplicationHelper.getInstance().init(this);
// IWXAPI 是第三方app和微信通信的openApi接口
        new MyThread().start();
//        registerActivityLifecycleCallbacks(new ActivityLifecycleListener());
        try {
            manager = new ScanManager();
            manager.switchOutputMode(0);
            Triggering mode = Triggering.CONTINUOUS ;    //Set the HOST mode
            manager.setTriggerMode(mode);
        } catch (Exception e) {
            e.printStackTrace();
        }
//
    }

    class MyThread extends Thread {
        @Override
        public void run() {
            super.run();
            ProvinceDataBean.getInstance();
            //干你需要做的操作
        }
    }

    public boolean isBackground(Context context) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
                .getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
            if (appProcess.processName.equals(context.getPackageName())) {
                /*
                BACKGROUND=400 EMPTY=500 FOREGROUND=100
                GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
                 */
                Log.i(context.getPackageName(), "此appimportace ="
                        + appProcess.importance
                        + ",context.getClass().getName()="
                        + context.getClass().getName());
                if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    Log.i(context.getPackageName(), "处于后台"
                            + appProcess.processName);

                    return true;
                } else {
                    Log.i(context.getPackageName(), "处于前台"
                            + appProcess.processName);
                    return false;
                }
            }
        }
        return false;
    }
}
